package fl.ass.service.api;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.IPriorityApiService;
import cmm.user.facade.system.dto.SysUsrDatAuthRDTO;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.overdue.constant.RskTaskConstant;
import cn.fl.overdue.service.IOverdueApiService;
import cn.fl.project.constant.PrjPrdDtlConstant;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.dto.PrjPrdPaySchMDTO;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.risknew.dto.RskUsrCstRDTO;
import cn.fl.risknew.service.IRskUsrCstRNewApiService;
import com.alibaba.fastjson.JSON;
import fl.ass.facade.api.IAssTrailCarApi;
import fl.ass.facade.condition.*;
import fl.ass.facade.constant.InterfaceConstants;
import fl.ass.facade.dto.*;
import fl.ass.service.config.NacosConfiguration;
import fl.ass.service.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AssTrailCarApi implements IAssTrailCarApi {
	
	private static final Logger logger = LoggerFactory.getLogger(AssTrailCarApi.class);

	@Autowired
	private IAssTrailCarMService assTrailCarMService;
	
	@Autowired
	private IAssTrailCarDService assTrailCarDService;
	
	@Autowired
	private IAssTrailCarDInfService assTrailCarDInfService;
	
	@Autowired
	private IAssDealRecAmtService assDealRecAmtService;
	
	/**
	 * 权限服务层BEAN
	 */
	@Autowired
	private IPriorityApiService priorityApiService;

    @Autowired
    private IAssTrailCarChannelService assTrailCarChannelService;

    @Autowired
    private IAssDealSellCostService assDealSellCostService;


    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;

    @Autowired
    private IProjectApiService projectApiService;

    @Autowired
    private NacosConfiguration nacosConfiguration;


	@Override
	public Pager findTrailCarApplyListByPage(Pager page) {
		AssTrailCarDQueryCondition condition = (AssTrailCarDQueryCondition)page.getCondition();
		if(null != condition){
			String backStsCd = condition.getBackStsCd();
			//针对拖车状态-未申请特殊处理
			if(StringUtils.isNotBlank(backStsCd) && "0".equals(backStsCd)){
				condition.setBackStsCd(null);
				condition.setStatus(backStsCd);
			}
			if(null != condition.getUsrId() && StringUtils.isNotBlank(condition.getSysCd())){
				try {
					//需要权限
					List<SysUsrDatAuthRDTO> usrDatAuthRList = this.priorityApiService.searchSysUsrDatAuthRWithOrgCdList(condition.getUsrId(),null,condition.getSysCd());
			        if(CollectionUtils.isNotEmpty(usrDatAuthRList)){
			        	condition.setUsrDatAuthRList(usrDatAuthRList);
					}
				} catch (Exception e) {
                    BaseLogUtils.newLogger("获取用户数据权限失败").setThrowable(e).setKeys("page:" + JSON.toJSONString(page)).info();
				}
			}
		}
		return assTrailCarDService.findTrailCarApplyListByPage(page);
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findTrailCarByPager(cmm.mid.core.framework.page.Pager)
	 */
	@Override
	public Pager findTrailCarByPager(Pager page) {
		AssTrailCarDQueryCondition condition = (AssTrailCarDQueryCondition)page.getCondition();
		if(null != condition){
			if(null != condition.getUsrId() && StringUtils.isNotBlank(condition.getSysCd())){
				try {
					//需要权限
					List<SysUsrDatAuthRDTO> usrDatAuthRList = this.priorityApiService.searchSysUsrDatAuthRWithOrgCdList(condition.getUsrId(),null,condition.getSysCd());
			        if(CollectionUtils.isNotEmpty(usrDatAuthRList)){
			        	condition.setUsrDatAuthRList(usrDatAuthRList);
					}
				} catch (Exception e) {
                    BaseLogUtils.newLogger("获取用户数据权限失败").setThrowable(e).setKeys("page:" + JSON.toJSONString(page)).error(LogExceptionEnum.COMMON_CODE_0002);
                    throw e;
				}
			}
		}
		return assTrailCarDService.findTrailCarListByPage(page);
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findTrailCarApplyListByPaySchIds(java.util.List)
	 */
	@Override
	public MessageDTO<AssTrailCarDDTO> findTrailCarApplyListByPaySchIds(List<Long> paySchIds) {
		MessageDTO<AssTrailCarDDTO> response = new MessageDTO<AssTrailCarDDTO>();
		if(null == paySchIds){
			response.setMessage("parameter：paySchIds is can not be null");
		}
		try {
			List<AssTrailCarDDTO> dtos = assTrailCarDService.findTrailCarApplyListByPaySchIds(paySchIds);
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setKeys("paySchIds:" + JSON.toJSONString(paySchIds)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findOrgInfoByPaySchId(java.lang.Long)
	 */
	@Override
	public MessageDTO<AssTrailCarDDTO> findOrgInfoByPaySchId(Long paySchId) {
		MessageDTO<AssTrailCarDDTO> response = new MessageDTO<AssTrailCarDDTO>();
		if(null == paySchId){
			response.setMessage("parameter：paySchId is can not be null");
		}
		try {
			AssTrailCarDDTO dto = assTrailCarDService.findOrgInfoByPaySchId(paySchId);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setKeys("paySchId:" + paySchId).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#updateAssTrailCarDetailInfo(fl.ass.facade.dto.AssTrailCarDDTO)
	 */
	@Override
	public MessageDTO<String> updateAssTrailCarDetailInfo(AssTrailCarDDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		if(null == dto){
			response.setMessage("parameter：dto is can not be null");
		}
		try {
			assTrailCarDService.updateAssTrailCarDetailInfo(dto);
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#updatePayStatus(java.util.List)
	 */
	@Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=BaseException.class)
	public MessageDTO<String> updatePayStatus(List<ProductStatusLogDTO> dtos) throws BaseException{
		MessageDTO<String> response = new MessageDTO<String>();
		if(null == dtos){
			response.setMessage("parameter：dtos is can not be null");
		}
		try {
			assTrailCarDService.updatePayStatus(dtos);

			response.setSuccess(true);
		} catch (BaseException e) {
            BaseLogUtils.newLogger("修改支付表状态失败" + e.getMessage()).setKeys("dtos:" + JSON.toJSONString(dtos)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
        } catch (Exception e) {
            BaseLogUtils.newLogger("修改支付表状态失败" + e.getMessage()).setKeys("dtos:" + JSON.toJSONString(dtos)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findTrailCarApplyListByIds(java.util.List)
	 */
	@Override
	public MessageDTO<AssTrailCarDDTO> findTrailCarDetailListByIds(List<Long> ids) {
		MessageDTO<AssTrailCarDDTO> response = new MessageDTO<AssTrailCarDDTO>();
		if(null == ids){
			response.setMessage("parameter：ids is can not be null");
		}
		try {
			List<AssTrailCarDDTO> dtos = assTrailCarDService.findTrailCarDetailListByIds(ids);
            BaseLogUtils.newLogger("不分页查询拖车明细参数：").setBussinessId(JSON.toJSONString(ids)).info();
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findAssTrailCarMasterById(java.lang.Long)
	 */
	@Override
	public MessageDTO<AssTrailCarMDTO> findAssTrailCarMasterById(Long applyId) {
		MessageDTO<AssTrailCarMDTO> response = new MessageDTO<AssTrailCarMDTO>();
		if(null == applyId){
			response.setMessage("parameter：applyId is can not be null");
		}
		try {
			AssTrailCarMDTO dto = assTrailCarMService.selectById(applyId);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	@Override
	public MessageDTO<AssTrailCarDDTO> findTrailCarDetailListById(Long applyId) {
		MessageDTO<AssTrailCarDDTO> response = new MessageDTO<AssTrailCarDDTO>();
		if(null == applyId){
			response.setMessage("parameter：ids is can not be null");
		}
		try {
			AssTrailCarDQueryCondition condition = new AssTrailCarDQueryCondition();
			condition.setMasterId(applyId);
			condition.setIsHis(InterfaceConstants.IS_DEL_0);
			condition.setIsDel(InterfaceConstants.IS_HIS_0);
			List<AssTrailCarDDTO> dtos = assTrailCarDService.searchList(condition);
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
		    BaseLogUtils.newLogger("查询拖车明细失败").setKeys("applyId:" + applyId).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		    throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#saveAssTrailCarInfo(fl.ass.facade.dto.AssTrailCarMDTO)
	 */
	@Override
	public MessageDTO<String> saveAssTrailCarInfo(AssTrailCarMDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		if(null == dto){
			response.setMessage("parameter：dto is can not be null");
		}
		try {
			//返回拖车主表ID-JL-20170320
			Long trailCarId = assTrailCarDService.saveAssTrailCar(dto);
			response.setId(trailCarId);
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/* (non-Javadoc)
	 * @see fl.ass.facade.api.IAssTrailCarApi#findTrailCarDetailListByDetailIds(java.util.List)
	 */
	@Override
	public MessageDTO<AssTrailCarDInfDTO> findTrailCarDetailListByDetailIds(List<Long> detailIds) {
		MessageDTO<AssTrailCarDInfDTO> response = new MessageDTO<AssTrailCarDInfDTO>();
		if(null == detailIds){
			response.setMessage("parameter：detailIds is can not be null");
		}
		try {
			AssTrailCarDInfQueryCondition condition = new AssTrailCarDInfQueryCondition();
			condition.setDetailIds(detailIds);
			List<AssTrailCarDInfDTO> dtos = assTrailCarDInfService.searchList(condition);
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("异常!" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/**
	 * 根据表名查询主键
	 */
	@Override
	public Long getPkId(String tabNm) throws BaseException {
		if(StringUtils.isEmpty(tabNm)){
			BaseLogUtils.newLogger("获取主键,表名参数为空").info();
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "表名不能为空!");
		}
		
		try {
			Long id = assTrailCarDService.getPkId(tabNm);
			return id;
		} catch (Exception e) {
			BaseLogUtils.newLogger("获取主键失败.[tabNm="+tabNm+"]").setKeys("tabNm:" + tabNm).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
			throw e;
		}
	}
	
	/**
	 * 保存拖车信息明细表
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> saveAssTrailCarD(AssTrailCarDDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			Long id = assTrailCarDService.add(dto);
			response.setId(id);//返回ID值
			response.setSuccess(true);
		} catch (Exception e) {
		    BaseLogUtils.newLogger("保存拖车信息明细表失败").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		    throw e;
		}
		return response;
	}
	
	/**
	 * 保存拖车信息主表
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> saveAssTrailCarM(AssTrailCarMDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			Long id = assTrailCarMService.add(dto);
			response.setId(id);//返回ID值
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("保存拖车信息主表失败").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
     * 拖车模块-发起流程
     * @param qc
     * @return
     * @throws BaseException
     */
	@Override
    public DataResultDTO addTrailCarApply(AssTrailCarDQueryCondition qc) throws BaseException{
        return this.assTrailCarDService.addTrailCarApply(qc);
    }
	
	/**
	 * 修改GPS在线状态信息
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> updateOnLineSt(AssTrailCarDDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			boolean flag = this.assTrailCarDService.modify(dto);
			response.setSuccess(flag);
		} catch (Exception e) {
            BaseLogUtils.newLogger("修改GPS在线状态信息").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
     * 不分页查询拖车明细
     * @author JiLi
     * @param condition
     * @return
     */
	@Override
    public List<AssTrailCarDDTO> searchDetailList(AssTrailCarDQueryCondition condition) throws BaseException {
		if(null == condition){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"查询对象不能为空!");
		}
		List<AssTrailCarDDTO> list = this.assTrailCarDService.searchList(condition);
		BaseLogUtils.newLogger("不分页查询拖车明细结果").setBussinessId("MasterId:" + condition.getMasterId()).setKeys("list:" + JSON.toJSONString(list)).info();
		return list;
	}
	
	/**
	 * 修改拖车主表信息
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> modifyMaster(AssTrailCarMDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			boolean flag = this.assTrailCarMService.modify(dto);
			response.setSuccess(flag);
		} catch (Exception e) {
            BaseLogUtils.newLogger("修改拖车主表信息").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
	 * 保存拖车实际明细表信息
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> saveAssTrailCarDInf(AssTrailCarDInfDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			Long id = assTrailCarDInfService.add(dto);
			response.setId(id);//返回ID值
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("保存拖车实际明细表信息").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
	 * 修改拖车实际明细表信息
	 * @param dto
	 * @return
	 */
	@Override
	public MessageDTO<String> modifyTrailCarDInf(AssTrailCarDInfDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			boolean flag = this.assTrailCarDInfService.modify(dto);
			response.setSuccess(flag);
		} catch (Exception e) {
            BaseLogUtils.newLogger("修改拖车实际明细表信息").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
	 * 查询拖车实际明细表信息
	 * @param id
	 * @return
	 */
	@Override
	public MessageDTO<AssTrailCarDInfDTO> findAssTrailCarDInfById(Long id) {
		MessageDTO<AssTrailCarDInfDTO> response = new MessageDTO<AssTrailCarDInfDTO>();
		if(null == id){
			response.setMessage("parameter：applyId is can not be null");
		}
		try {
			AssTrailCarDInfDTO dto = assTrailCarDInfService.selectById(id);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("查询拖车实际明细表信息").setKeys("id:" + JSON.toJSONString(id)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	@Override
	public MessageDTO<AssTrailCarDInfDTO> findPayInfoListByPaySchIds(List<Long> paySchIds) {
		MessageDTO<AssTrailCarDInfDTO> response = new MessageDTO<AssTrailCarDInfDTO>();
		if(null == paySchIds){
			response.setMessage("parameter：paySchIds is can not be null");
		}
		try {
			List<AssTrailCarDInfDTO> dtos = assTrailCarDInfService.findPayInfoListByPaySchIds(paySchIds);
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("findPayInfoListByPaySchIds 异常").setKeys("paySchIds:" + JSON.toJSONString(paySchIds)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
	 * 导出拖车模块信息
	 * @param orgCd
	 * @return
	 * @throws BaseException
	 */
	@Override
	public String exportAssInfo(AssTrailCarDQueryCondition qc1, AssDealCarQueryCondition qc2, AssTrailCarHvQueryCondition qc3,String orgCd, String eFlag) throws BaseException {
		if(StringUtils.isEmpty(orgCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "组织架构代码不能为空.");
		}
		if(null==qc1 && null==qc2 && null==qc3 ){
			//throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "查询条件不能为空.");
		}
		//拖车管理/申请-数据权限控制
		if(null != qc1 && null != qc1.getUsrId() && StringUtils.isNotBlank(qc1.getSysCd())){
			try {
				//需要权限
				List<SysUsrDatAuthRDTO> usrDatAuthRList = this.priorityApiService.searchSysUsrDatAuthRWithOrgCdList(qc1.getUsrId(),null,qc1.getSysCd());
		        if(CollectionUtils.isNotEmpty(usrDatAuthRList)){
		        	qc1.setUsrDatAuthRList(usrDatAuthRList);
				}
			} catch (Exception e) {
                BaseLogUtils.newLogger("获取用户数据权限失败").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
                throw e;
			}
		}
		//优车管理-数据权限控制
		if(null != qc2 && null != qc2.getUsrId() && StringUtils.isNotBlank(qc2.getSysCd())){
			try {
				//需要权限
				List<SysUsrDatAuthRDTO> usrDatAuthRList = this.priorityApiService.searchSysUsrDatAuthRWithOrgCdList(qc2.getUsrId(),null,qc2.getSysCd());
		        if(CollectionUtils.isNotEmpty(usrDatAuthRList)){
		        	qc2.setUsrDatAuthRList(usrDatAuthRList);
				}
			} catch (Exception e) {
                BaseLogUtils.newLogger("获取用户数据权限失败").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
                throw e;

			}
		}
		//库管管理-数据权限控制
		if(null != qc3 && null != qc3.getUsrId() && StringUtils.isNotBlank(qc3.getSysCd())){
			try {
				//需要权限
				List<SysUsrDatAuthRDTO> usrDatAuthRList = this.priorityApiService.searchSysUsrDatAuthRWithOrgCdList(qc3.getUsrId(),null,qc3.getSysCd());
		        if(CollectionUtils.isNotEmpty(usrDatAuthRList)){
		        	qc3.setUsrDatAuthRList(usrDatAuthRList);
				}
			} catch (Exception e) {
                BaseLogUtils.newLogger("获取用户数据权限失败").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
                throw e;
			}
		}
		return this.assTrailCarMService.exportAssInfo(qc1, qc2, qc3,orgCd, eFlag);
	}

	@Override
	public MessageDTO<AssDealRecAmtDTO> searchAssDealRectAmtList(
			AssDealRecAmtQueryCondition con) {
		MessageDTO<AssDealRecAmtDTO> response = new MessageDTO<AssDealRecAmtDTO>();
		try {
			List<AssDealRecAmtDTO> dtos = assDealRecAmtService.searchList(con);
			if(null != dtos){
				response.setDatas(dtos);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("searchAssDealRectAmtList 异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}

	/**
	 * 更新处置收款信息
	 * @return
	 * @throws BaseException
	 */
	@Override
	public MessageDTO<String> modifyAssDealRectAmt(
			AssDealRecAmtDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			boolean flag = this.assDealRecAmtService.modifyAssDealRectAmt(dto);
			response.setSuccess(flag);
		} catch (Exception e) {
            BaseLogUtils.newLogger("modifyAssDealRectAmt 异常").setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	/**
	 * 保存处置收款信息
	 * @param dto
	 * @return
	 * @throws BaseException
	 */
	@Override
	public MessageDTO<String> saveAssDealRectAmt(AssDealRecAmtDTO dto) {
		MessageDTO<String> response = new MessageDTO<String>();
		try {
			Long id = this.assDealRecAmtService.add(dto);
			response.setId(id);//返回ID值
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("保存处置收款信息异常").setKeys("dto:" + JSON.toJSONString(dto)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/* 
	 * 查询（处置收款表） 
	 */
	@Override
	public MessageDTO<AssDealRecAmtDTO> selectAssDealRecAmtById(Long id) throws BaseException {
		MessageDTO<AssDealRecAmtDTO> response = new MessageDTO<AssDealRecAmtDTO>();
		if(null == id){
			response.setMessage("parameter：id is can not be null");
		}
		try {
			AssDealRecAmtDTO dto = assDealRecAmtService.selectById(id);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("查询（处置收款表）异常").setKeys("id:" + id).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/* 
	 * 删除（处置收款表） 
	 */
	@Override
	public MessageDTO<String> removeAssDealRecAmtById(Long id) throws BaseException {
		MessageDTO<String> response = new MessageDTO<String>();
		if(null == id){
			response.setMessage("parameter：idis can not be null");
		}
		try {
			boolean flag = assDealRecAmtService.removeById(id);
			response.setSuccess(flag);
		} catch (Exception e) {
            BaseLogUtils.newLogger("删除（处置收款表）异常").setKeys("id:" + id).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	
	/**
     * 根据项目ID查询拖车模块相关流程业务主键列表
     * 返回值形式：Map<paySchNo,List<Long> dateIdList>
     * @param prjId
     * @return
     * @throws BaseException
     */
	@Override
    public Map<String,List<Long>> getAssDateIdList(Long prjId)throws BaseException{
		Map<String,List<Long>> resultMap = new HashMap<String,List<Long>>();
		try {
			resultMap = assTrailCarDService.getAssDateIdList(prjId);
		} catch (Exception e) {
			BaseLogUtils.newLogger("获取拖车模块流程业务主键失败").setThrowable(e).setKeys("prjId:" + prjId).error(LogExceptionEnum.COMMON_CODE_0002);
			throw e;
		}
		return resultMap;
    }
	
	/* 
	 * 查询（拖车明细表） 
	 */
	@Override
	public MessageDTO<AssTrailCarDDTO> selectAssTrailCarDById(Long id) throws BaseException {
		MessageDTO<AssTrailCarDDTO> response = new MessageDTO<AssTrailCarDDTO>();
		if(null == id){
			response.setMessage("parameter：id is can not be null");
		}
		try {
			AssTrailCarDDTO dto = assTrailCarDService.selectById(id);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("查询（拖车明细表）").setKeys("id:" + id).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
			throw e;
		}
		return response;
	}

	/**
	 * 根据业务主键查询流程号和支付表号
	 * @param dataId 业务主键
	 * @return 
	 */
	@Override
	public MessageDTO<AssTrailCarDInfDTO> selectPNoPaySchNoByDataId(Long dataId) throws BaseException {
		MessageDTO<AssTrailCarDInfDTO> response = new MessageDTO<AssTrailCarDInfDTO>();
		if(null == dataId){
			response.setMessage("parameter：dataId is can not be null");
		}
		try {
			AssTrailCarDInfDTO dto = assTrailCarDInfService.selectPNoPaySchNoByDataId(dataId);
			if(null != dto){
				response.setData(dto);
			}
			response.setSuccess(true);
		} catch (Exception e) {
            BaseLogUtils.newLogger("根据业务主键查询流程号和支付表号异常").setKeys("dataId:" + dataId).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
		}
		return response;
	}
	@Override
	public MessageDTO<AssTrailCarDInfDTO> searchAssTrailCarDInfList(AssTrailCarDInfQueryCondition condition) throws BaseException {
        MessageDTO<AssTrailCarDInfDTO> response = new MessageDTO<AssTrailCarDInfDTO>();
        if (null == condition.getDetailId() && null == condition.getDetailIds()) {
            response.setMessage("parameter：ids is can not be null");
        }
        try {
            List<AssTrailCarDInfDTO> dtos = assTrailCarDInfService.searchList(condition);
            if (null != dtos) {
                response.setDatas(dtos);
            }
            response.setSuccess(true);
        } catch (Exception e) {
            BaseLogUtils.newLogger("查询拖车实际明细异常!").setKeys("condition:" + JSON.toJSONString(condition)).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            throw e;
        }
        return response;
    }

    @Override
    public List<AssTrailCarMDTO> selectList(AssTrailCarMQueryCondition qc) throws BaseException {
        if(null == qc) return new ArrayList<AssTrailCarMDTO>();
        return this.assTrailCarMService.searchList(qc);
    }

    @Override
    public List<AssTrailCarMDTO> selectListByChnIds(AssTrailCarMQueryCondition condition) throws BaseException {
        if(null == condition) return new ArrayList<AssTrailCarMDTO>();
        return this.assTrailCarMService.selectListByChnIds(condition);
    }

	@Override
	public List<AssDealSellCostDTO> selectAssDealSellCostList(AssDealSellCostQC qc)
			throws BaseException {
		if(null==qc) return new ArrayList<AssDealSellCostDTO>();
		return this.assDealSellCostService.searchList(qc);
	}

	@Override
	public Pager searchAssDealSellCostListPage(Pager page) throws BaseException {
		if(null==page) page = new Pager();
		return this.assDealSellCostService.searchListPage(page);
	}

	@Override
	public boolean batchAddAssDealSellCost(List<AssDealSellCostDTO> dtoList)
			throws BaseException {
		if(CollectionUtils.isEmpty(dtoList)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.assDealSellCostService.batchAddAssDealSellCost(dtoList);
	}

	@Override
	public boolean deleteAddAssDealSellCostbyId(Long id) throws BaseException {
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "删除数据主键ID不能为空.");
		}
		return this.assDealSellCostService.removeById(id);
	}

	/**
	 * 根据条件查询是否存在拖车记录
	 *
	 * @param condition
	 * @return
	 * @throws BaseException
	 */
	@Override
	public boolean searchIsExistsTrail(AssTrailCarDQueryCondition condition) throws BaseException {
		List<AssTrailCarDDTO> list = this.assTrailCarDService.searchList(condition);
		if(CollectionUtils.isNotEmpty(list)){
			return true;
		}
		return false;
	}

    @Override
    public List<Long> searchPrjPrdPaySchIdsByPrjPrdDtlId(Long prjPrdDtlId) throws BaseException {
        return this.assTrailCarMService.searchPrjPrdPaySchIdsByPrjPrdDtlId(prjPrdDtlId);
    }

    @Override
    public void updateYQPrdStsCdByFlow(ProductStatusLogDTO productStatusLogDTO) throws BaseException {
        this.assTrailCarMService.updateYQPrdStsCdByFlow(productStatusLogDTO);
    }

    @Override
    public boolean checkDealOrTransUsedFlowStart(Long assMainId) throws BaseException {
        return this.assTrailCarMService.checkDealOrTransUsedFlowStart(assMainId);
    }

    @Override
    public String getProp() throws BaseException {
        return nacosConfiguration.getUlfilesRootPath();
    }

}
